/* eslint-disable import/prefer-default-export */
import React, { useState, useEffect } from 'react';
import { Row, Col, Spin, Empty, Icon } from 'antd';
import { eventTrack } from '@/utils/track';
import { history } from 'umi';
import cn from 'classnames';
import { getcompanylist, getmylist, getmyofferlist } from '@/services/notice/homePage';
import { getManegelist } from '@/services/myRecruit/candidate';
import { queryleaderinterviews } from '@/services/myRecruit/interview';
import LinkTo from '@/components/LinkTo';
import styles from './index.less';
import { getValue } from './useHooks';

/**
 * 招聘任务
 */
export const RecruitmentTask = () => {
    const [spinning, setSpinning] = useState(false);
    const [sourceData, setSourceData] = useState([]);
    const user = localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')) : {};
    const params = {
        pageNo: 1,
        pageSize: 4,
        employeeCode: user.employeeCode
    };
    useEffect(() => {
        const init = async () => {
            setSpinning(true);
            const res = await getmylist(params);
            setSpinning(false);
            if (res && res.code === 10000) {
                setSourceData(res.data.rows);
            }
        };
        init();
    }, []);
    return (
        <Spin spinning={spinning}>
            {sourceData.length === 0 ? (
                <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
            ) : (
                sourceData.map(item => {
                    const innerParams = {
                        recruitCode: item.recruitCode,
                        companyId: item.companyId,
                        applicationNo: item.applicationNo
                    };
                    return (
                        <div className={styles.tabPaneItem} key={item.id}>
                            <Row gutter={4}>
                                <Col span={8}>
                                    <LinkTo
                                        to="/personal/portal/recruit/task/positiondetails"
                                        query={innerParams}
                                        title={item.recruitPost}
                                        className={styles.title}
                                    >
                                        {item.recruitPost}
                                    </LinkTo>
                                </Col>
                                <Col span={8}>{item.scheduleName}</Col>
                                <Col span={8} className={styles.lastTab}>
                                    {item.applyDate}
                                </Col>
                            </Row>
                        </div>
                    );
                })
            )}
        </Spin>
    );
};
/**
 * 招聘需求
 */
export const RecruitmentNeeds = () => {
    const [spinning, setSpinning] = useState(false);
    const [sourceData, setSourceData] = useState([]);
    const user = localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')) : {};
    const params = {
        pageNo: 1,
        pageSize: 4,
        userCode: user.userCode
    };
    useEffect(() => {
        const init = async () => {
            setSpinning(true);
            const res = await getcompanylist(params);
            setSpinning(false);
            if (res && res.code === 10000) {
                setSourceData(res.data.rows);
            }
        };
        init();
    }, []);
    return (
        <Spin spinning={spinning}>
            {sourceData.length === 0 ? (
                <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
            ) : (
                sourceData.map(item => {
                    const innerParams = {
                        recruitCode: item.recruitCode,
                        companyId: item.companyId,
                        applicationNo: item.applicationNo
                    };
                    return (
                        <div className={styles.tabPaneItem}>
                            <Row gutter={4}>
                                <Col span={8}>
                                    <LinkTo
                                        to="/personal/portal/recruit/demand/positiondetails"
                                        query={innerParams}
                                        title={item.recruitPost}
                                        className={styles.title}
                                    >
                                        {item.recruitPost}
                                    </LinkTo>
                                </Col>
                                <Col span={8}>{item.scheduleName}</Col>
                                <Col span={8} className={styles.lastTab}>
                                    {item.applyDate}
                                </Col>
                            </Row>
                        </div>
                    );
                })
            )}
        </Spin>
    );
};
/**
 * 候选人
 */
export const Candidate = () => {
    const [spinning, setSpinning] = useState(false);
    const [sourceData, setSourceData] = useState([]);
    const params = {
        pageNo: 1,
        pageSize: 4
    };
    useEffect(() => {
        const init = async () => {
            setSpinning(true);
            const res = await getManegelist(params);
            setSpinning(false);
            if (res && res.code === 10000) {
                setSourceData(res.data.rows);
            }
        };
        init();
    }, []);
    return (
        <Spin spinning={spinning}>
            {sourceData.length === 0 ? (
                <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
            ) : (
                sourceData.map(item => {
                    const { candidateCode, isInterview, isApplyOffer } = item;
                    return (
                        <div className={styles.tabPaneItem}>
                            <Row gutter={4}>
                                <Col span={6}>
                                    <LinkTo
                                        // 埋点
                                        onClick={async (e, url) => {
                                            await eventTrack({
                                                eventName: 'personal_portal_recruit_candidate_detail_click',
                                                eventProps: { label: '个人主页-我的招聘-候选人详情' }
                                            });
                                            history.push(url);
                                        }}
                                        to="/personal/portal/recruit/candidate/detail"
                                        query={{
                                            candidateCode,
                                            isInterview: isInterview.toString(),
                                            isApplyOffer: isApplyOffer.toString()
                                        }}
                                        title={item.talentName}
                                        className={styles.title}
                                    >
                                        {item.talentName}
                                    </LinkTo>
                                    <Icon
                                        className={cn(
                                            styles.sex,
                                            styles[`sex-${item.talentSex === '1' ? 'man' : 'woman'}`]
                                        )}
                                        type={item.talentSex === '1' ? 'man' : 'woman'}
                                    />
                                </Col>
                                <Col span={6}>{item.recruitPost}</Col>
                                <Col span={6}>{item.candidateStageValue}</Col>
                                <Col span={6} className={styles.lastTab}>
                                    {item.candidateStateValue}
                                </Col>
                            </Row>
                        </div>
                    );
                })
            )}
        </Spin>
    );
};
/**
 * 面试
 */
export const Interview = () => {
    const [spinning, setSpinning] = useState(false);
    const [sourceData, setSourceData] = useState([]);
    const params = {
        pageNo: 1,
        pageSize: 4
    };
    useEffect(() => {
        const init = async () => {
            setSpinning(true);
            const res = await queryleaderinterviews(params);
            setSpinning(false);
            if (res && res.code === 10000) {
                setSourceData(res.data.rows);
            }
        };
        init();
    }, []);
    return (
        <Spin spinning={spinning}>
            {sourceData.length === 0 ? (
                <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
            ) : (
                sourceData.map(item => (
                    <div className={styles.tabPaneItem}>
                        <Row gutter={4}>
                            <Col span={6} title={item.talentName}>
                                {item.isEditRecord ? (
                                    <LinkTo
                                        className={styles.title}
                                        to="/personal/portal/recruit/interview/edit"
                                        query={{
                                            arrangeCode: item.interviewArrangeCode,
                                            code: item.candidateCode,
                                            type: 'type2'
                                        }}
                                    >
                                        {item.talentName}
                                    </LinkTo>
                                ) : (
                                    <LinkTo
                                        className={styles.title}
                                        to="/personal/portal/recruit/interview/edit"
                                        query={{
                                            arrangeCode: item.interviewArrangeCode,
                                            code: item.candidateCode,
                                            type: 'type4'
                                        }}
                                    >
                                        {item.talentName}
                                    </LinkTo>
                                )}
                                {item.talentSexValue === '女' ? (
                                    <i
                                        className="iconfont iconoa_table_icon_women_default"
                                        style={{
                                            color: '#f2637b',
                                            margin: '0 5px'
                                        }}
                                    />
                                ) : (
                                    <i
                                        className="iconfont iconoa_table_icon_men_default"
                                        style={{
                                            color: '#3aa0ff',
                                            margin: '0 5px'
                                        }}
                                    />
                                )}
                            </Col>
                            <Col span={6} title={item.recruitPost}>
                                {item.recruitPost}
                            </Col>
                            <Col span={6} title={item.interviewTime}>
                                {item.interviewTime}
                            </Col>
                            <Col span={6} className={styles.lastTab} title={item.interviewConclusionValue}>
                                {item.interviewConclusionValue}
                            </Col>
                        </Row>
                    </div>
                ))
            )}
        </Spin>
    );
};
/**
 * offer
 */
export const Offer = () => {
    const [spinning, setSpinning] = useState(false);
    const [sourceData, setSourceData] = useState([]);
    const user = localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')) : {};
    const params = {
        pageNo: 1,
        pageSize: 4,
        leaderIds: user.id ? [user.id] : []
    };
    useEffect(() => {
        const init = async () => {
            setSpinning(true);
            const res = await getmyofferlist(params);
            setSpinning(false);
            if (res && res.code === 10000) {
                setSourceData(res.data.rows);
                // setSourceData([
                //     {
                //         talentName: '姓名',
                //         entryPostName: '应聘职位',
                //         offerProcessStatus: 'offer流程进度',
                //         offerStateName: 'offer状态'
                //     }
                // ]);
            }
        };
        init();
    }, []);
    return (
        <Spin spinning={spinning}>
            {sourceData.length === 0 ? (
                <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
            ) : (
                sourceData.map(item => (
                    <div className={styles.tabPaneItem}>
                        <Row gutter={5}>
                            <Col span={6}>
                                <LinkTo
                                    to="/personal/portal/recruit/offer/detail"
                                    query={{
                                        offerCode: item.offerCode
                                    }}
                                    className={styles.title}
                                >
                                    {item.talentName}
                                </LinkTo>
                                <Icon
                                    className={cn(
                                        styles.sex,
                                        styles[`sex-${item.talentSex === '1' ? 'man' : 'woman'}`]
                                    )}
                                    type={item.talentSex === '1' ? 'man' : 'woman'}
                                />
                            </Col>
                            <Col span={6}>{item.entryPostName}</Col>
                            <Col span={6}>{getValue(item.offerProcessStatus)}</Col>
                            <Col span={6} className={styles.lastTab}>
                                {item.offerStateName || '---'}
                            </Col>
                        </Row>
                    </div>
                ))
            )}
        </Spin>
    );
};
